package com.yanqu.road.server.cmd.activity.bowart;

import com.yanqu.road.pb.activity.BowArtProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.bowart.BowArtModule;
import com.yanqu.road.server.manger.activity.bowart.BowArtMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = GameProtocol.S_BOW_ART_ACTIVITY_SMELT, desc = "熔炼")
public class BowArtSmeltCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        if(BowArtMgr.getShowTimeActivityId() == 0){
            ret = GameErrorCode.E_ACTIVITY_NO_FOUND;
            return;
        }
        if(!BowArtMgr.activityInTime()){
            ret = GameErrorCode.E_BOW_ART_ACTIVITY_NO_IN_TIME;
            return;
        }
        ret = player.getModule(BowArtModule.class).smelt();
    }

    @Override
    public void sendData(GamePlayer player) {
        if(ret != 0){
            BowArtProto.BowArtSmeltRespMsg.Builder respMsg = BowArtProto.BowArtSmeltRespMsg.newBuilder();
            respMsg.setRet(ret);
            player.sendPacket(Protocol.U_BOW_ART_ACTIVITY_SMELT, respMsg);
        }
    }
}
